1. Field of the Invention
This invention relates in general to the field of data processing in computers, and more particularly to an apparatus and method for performing push all/pop all stack access operations.
2. Description of the Related Art
An application program for execution on a microprocessor typically is divided into a number of subroutines. Each subroutine performs a particular function such as retrieving contents of an address in memory, adding two operands together, or outputting an operand to an address mapped to, say, a video display device. And, in today's desktop computer systems, applications and their constituent subroutines are designed so as to give the impression that they are executing at the same time on the microprocessor. For example, an operator desires to immediately view on a video monitor what is being input to the computer from a keyboard. Although a subroutine for reading keystrokes on the keyboard does not run on the microprocessor at the same instant as a subroutine to display characters on the video monitor, the two subroutines are designed to time share resources in the microprocessor so that it appears to the operator that the two events, input and display, happen simultaneously.
Additionally, a significant number of subroutines that are executed on a desktop computer system utilize the same microprocessor resources, such as general purpose registers in the microprocessor. Because most subroutines are designed to time share these resources, microprocessors provide certain instructions and associated logic to insure that transfer of microprocessor control from one subroutine to the next is convenient and effective.
Most often, subroutines utilize a stack structure in memory to temporarily store the contents of their associated registers prior to transferring control of the microprocessor. A stack is simply a block of memory at a designated address. Hence, prior to transferring control to Subroutine B, Subroutine A would first copy the contents of all of its working registers to the stack. As a result, Subroutine B is free to use the same registers without corrupting register contents associated with Subroutine A. When control is returned to Subroutine A, it would then retrieve contents of its working registers from the stack and continue execution.
Present day stacks are architecturally configured to store successive operands in adjacent memory locations. Hence, four successive store operations to a stack would result in operands being placed in four adjacent stack addresses. Additionally, three successive stack retrievals would result in operands being retrieved from three adjacent stack addresses. Stack usage is so prevalent today that most microprocessors provide dedicated instructions, i.e., stack access instructions, for storing data in a stack and retrieving data from the stack. One particular pair of stack access instructions is used to store/retrieve all of a microprocessor's general purpose registers to/from the stack. This instructions are commonly known as a push all instructions (PUSHA) and pop all instructions (POPA).
When a push all instruction is executed by a microprocessor, it is decoded by logic in the microprocessor into a sequence of push micro instructions, each push micro instruction directing the microprocessor to store one of the general purpose registers in the stack. A number of push micro instructions are generated equal to the number of general purpose registers. For instance, in an x86-compatible microprocessor, there are eight general purpose registers. Hence, a push all operation would result in the generation and execution of eight push micro instructions, each push micro instruction directing the microprocessor to store a different register. A pop all instruction is similarly executed, with the exception that the operands are retrieved from the stack and placed in all the general purpose registers rather than stored in the stack.
Although a microprocessor's registers are individually stored to or retrieved from the stack by the push/pop micro instructions, the microprocessor does not store/retrieve a number of bytes to/from the stack equal to the size of a general purpose register. Rather, the microprocessor is designed to store/retrieve data in larger-sized blocks. For example, in a typical microprocessor, an instruction to retrieve a 2-byte operand from memory would result in the microprocessor retrieving, say, and 8-byte block of data which contains the 2-byte operand.
For many types of instructions, accessing a larger-sized block of data than what is really required does not impose a burden on microprocessor performance. Yet, microprocessor designers continue to be challenged to increase the overall performance of a design by improving the efficiency of certain fundamental operations. Push all and pop all instructions are ripe for improvement, primarily because these instructions direct the microprocessor to perform multiple accesses to the stack to access multiple operands in adjacent addresses. It is highly probable, then, that a number of the multiple operands would be contained within the same larger-size block of data. Yet to have to repeatedly access the same larger-size block of data to access different operands is inefficient. A given operand in a larger-sized data block may conceivably be accessed a number of times during execution of a push all/pop all instruction. This is because the larger-sized data block, in addition to containing the given operand, contains other operands which are also prescribed for access by the push all/pop all instruction. And, because present day microprocessors do not provide the capability to combine accesses to a group of operands contained within the same larger-sized data block into a single access, the given operand is accessed each time the other operands in the larger-sized data block are accessed by the microprocessor. One skilled in the art will observe from the above that execution of push all/pop all instructions in a present day microprocessor wastes a great deal of valuable execution time.
Therefore, what is needed is a microprocessor which can store/retrieve two operands to/from a stack within a single access.
In addition, what is needed is an apparatus in a microprocessor to perform a push all/pop all operation wherein pairs of operands are accessed in a combined access.
Moreover, what is needed is a method for executing a push all/pop all instruction on a microprocessor that eliminates redundant memory accesses by combining accesses to a group of operands into a single access.